package model.feature;

import java.io.File;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import model.Settings;
import util.PlayerUtilities;

public class WeatherItems {

	private int Id;
	private String image;
	
	/*private String textTop;
	private String textBottom;
	private String textMiddle;*/
	
	private String maxTemp;
	private String minTemp;
	private String weatherInfo;
	private String weatherDate;
	private String weatherDay;
	
	private static WeatherItems _instance;

	private WeatherItems()
	{

	}

	public static WeatherItems getInstance()
	{
		if(_instance == null)
		{
			_instance = new WeatherItems();
		}
		return _instance;
	}

	@SuppressWarnings("unchecked")
	public Map<Integer, WeatherItems> getWeatherItemsList()
	{
		Map<Integer, WeatherItems> featureRecords = new HashMap<Integer, WeatherItems>();

		System.out.println(Settings.WEATHER_XML);
		if(!new File(Settings.WEATHER_XML).exists()){
			System.out.println("Doesn't exist");
			return featureRecords;
		}

		if (new File(Settings.WEATHER_XML).exists()) {
			Object obj = PlayerUtilities.getObjectFromXMLFile(Settings.WEATHER_XML);
			if (obj != null) {
				featureRecords = (Map<Integer, WeatherItems>) obj;
			} else {
				System.out.println("Failed to read " + Settings.WEATHER_XML);
			}
		}

		return featureRecords;
	}
	
	public void saveToXML() {
		System.out.println("saving feature to xml.");
		Map<Integer,WeatherItems> obj = getWeatherItemsList();
		PlayerUtilities.saveObjectToXMLFile(Settings.WEATHER_XML, obj);
		//PlayerUtilities.saveObjectToXMLFile(Settings.WEATHER_XML, this);
	}

	public int getId() {
		return Id;
	}

	public void setId(int id) {
		Id = id;
	}

	public String getImage() {
		return image;
	}

	public void setImage(String image) {
		this.image = image;
	}
	
	public String getMaxTemp() {
		return maxTemp;
	}

	public void setMaxTemp(String maxTemp) {
		this.maxTemp = maxTemp;
	}

	public String getMinTemp() {
		return minTemp;
	}

	public void setMinTemp(String minTemp) {
		this.minTemp = minTemp;
	}

	public String getWeatherInfo() {
		return weatherInfo;
	}

	public void setWeatherInfo(String weatherInfo) {
		this.weatherInfo = weatherInfo;
	}

	public String getWeatherDate() {
		return weatherDate;
	}

	public void setWeatherDate(String weatherDate) {
		this.weatherDate = weatherDate;
	}
	
	public String getWeatherDay() {
		return weatherDay;
	}

	public void setWeatherDay(String weatherDay) {
		this.weatherDay = weatherDay;
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		WeatherItems witems = WeatherItems.getInstance();
		//witems.saveToXML();
		Map<Integer, WeatherItems> obj = witems.getWeatherItemsList();
		
		Collection<Integer> keys = obj.keySet();
		
		for(int i : keys)
		{
			System.out.println(obj.get(i).getMaxTemp());
		}
	}

}
